package com.hq.sys.controller;

import com.hq.sys.eneity.RoleVo;
import com.hq.sys.service.RoleService;
import com.hq.sys.util.DataGridView;
import com.hq.sys.util.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsPackage: com.hq.sys.controller
 * @Author: jiangjunjie
 * @CreateTime: 2024-12-22  16:36
 * @Description: TODO
 * @Version: 1.8
 */
@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("initRoleMenuTreeJson")
    public DataGridView initRoleMenuTreeJson(Integer roleid){
        return roleService.initRoleMenuTreeList(roleid);
    }
    //查看所有角色
    @RequestMapping("loadAllRole")
    public DataGridView loadAllRole(RoleVo roleVo){
        return roleService.queryAllMenuForList(roleVo);
    }
    //添加角色
    @RequestMapping("addRole")
    public ResultObj addRole(RoleVo roleVo){
        try{
            this.roleService.addRole(roleVo);
            return ResultObj.ADD_SUCCESS;
        }catch (Exception e){
           return ResultObj.ADD_ERROR;
        }
    }
    //修改角色
    @RequestMapping("updateRole")
    public ResultObj updateRole(RoleVo roleVo){
        try {
            this.roleService.updateRole(roleVo);
            return ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            return ResultObj.UPDATE_ERROR;
        }
    }
    //删除角色
    @RequestMapping("deleteRole")
    public ResultObj deleteRole(Integer roleid){
        try {
            this.roleService.deleteRole(roleid);
            return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            return ResultObj.DELETE_ERROR;
        }
    }
    //批量删除角色
    @RequestMapping("deleteBatchRole")
    public ResultObj deleteBatchRole(Integer[] ids){
        try {
            this.roleService.deleteBatchRole(ids);
            return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            return ResultObj.DELETE_ERROR;
        }
    }
    //分配菜单
    @RequestMapping("saveRoleMenu")
    public ResultObj saveRoleMenu(RoleVo roleVo){
        try {
            this.roleService.saveRoleMenu(roleVo);
            return ResultObj.DISPATCH_SUCCESS;
        }catch (Exception e){
            return ResultObj.DISPATCH_ERROR;
        }
    }
}

